package com.qst.controller;

import com.qst.beans.DayIn;
import com.qst.beans.Product;
import com.qst.service.impl.OrderServiceImpl;
import com.qst.service.impl.ProductServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/echart")
public class AdminTongjiBijiao {

    @Resource
    private OrderServiceImpl orderService;
    @Autowired
    private ProductServiceImpl productService;/*is_hot就是商品加入购物车次数【未实现数据统一】，就是购买次数*/

    /*得到所有已被销售商品的销售情况*/
    @RequestMapping(value = "/adminEachartzhu")
    @ResponseBody
    public List<Product> getAllXiaoshou(){
        System.out.println("柱状图数据统计请求");
        /**
         * 得到各商品名称和商品销售数量(本应该让product表与orderitem表关联统计)
         */
        List<Product> productList = productService.findAll();
        List<Product> products= new ArrayList<>();
//        List<Map<String,Integer>> products = new ArrayList<>();
        for (Product p:productList
             ) {
            System.out.print(p.getIs_hot());
            if (p.getPname()!=null&&p.getPname()!=""&&p.getIs_hot()!=null&&p.getIs_hot()>0){
//                Map<String,Integer> map = new HashMap<>();
//                map.put(p.getPname(),p.getIs_hot());
                products.add(p);
//                products.add(map);
            }


        }
        return products;
    }

    /*跳转到销售柱状图页面*/
    @RequestMapping(value = "/toadminEachartzhu")
    public String toAdminEchart(){
        return "/admin/echart/xiaoshouZhu";
    }

    /*跳转到销售饼状图页面*/
    @RequestMapping(value = "/toadminEachartBin")
    public String  toadminEachartzhu2(){
        return "admin/echart/xiaoshouBin";
    }


    /*管理员权限查询近日订单金额*/
    @RequestMapping(value = "/getAllOrdersComeInByDate")
    @ResponseBody
    public List<DayIn> getAllOrdersComeInByDate(){
        System.out.println("管理员权限查询近日订单金额");
        List<DayIn> ordersComeInByDate = orderService.getAllOrdersComeInByDate();
        for (DayIn map:ordersComeInByDate){
            System.out.println(map);
        }
        return ordersComeInByDate;
    }
}
